package com.yby.dome8;

import com.yby.dome7.People;

public class Test {
    //判断animal对象属于Eagle、Frog、Caterpillar中的那一个类，判断完成之后再向下转型
    public void instanceOf(Animal animal){
        if (animal instanceof Eagle){
            Eagle eagle = (Eagle) animal;
        }
        if (animal instanceof Frog){
            Frog frog = (Frog) animal;
        }
        if (animal instanceof Caterpillar){
            Caterpillar caterpillar = (Caterpillar) animal;
        }
    }
    public static void main(String[] args) {
        Animal animal =new Eagle();
        Animal animal1 =new Frog();
        Animal animal2 =new Caterpillar();
        Test test = new Test();
        test.instanceOf(animal);
        animal.name = "苍鹰";
        animal.eat();
        test.instanceOf(animal1);
        animal1.name = "牛蛙";
        animal1.eat();
        test.instanceOf(animal2);
        animal2.name = "赤松毛虫";
        animal2.eat();
    }
}
